﻿

'*******************************************************************
' Program: Data Center Visio Rack Tool
' Author: Albert E Edlund
' Date:
'
' Purpose: load data for drawings
'
'
'*******************************************************************


Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging

Imports System.Data
Imports System.Drawing
Imports System.Text

Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Visio
Imports System.Runtime.InteropServices

Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Collections.ObjectModel



Public Class clsDC_RackData

#Region " Properties and Definitions "


    Public m_db As Database
    ' in most of the classes the m_ds is temporary, in this class we use it to store
    ' the datatables that relate to the current drawing
    Public m_ds As DataSet
    Public m_dt As DataTable

    Private m_clsVisio As visRackLocations.clsVisioSupport


    '********* visio snippet vb.net visXXXX ******************
    Private _drawingApplication As Microsoft.Office.Interop.Visio.Application
    Public Property drawingApplication() As Microsoft.Office.Interop.Visio.Application
        Get
            Return Me._drawingApplication
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Application)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("ApplicationValueIsNull", _
                    "drawingApplication is Null.")
            End If
            Me._drawingApplication = value
        End Set
    End Property

    '********* visio snippet vb.net visXXXX ******************
    Private _drawingDocument As Microsoft.Office.Interop.Visio.Document
    Public Property drawingDocument() As Microsoft.Office.Interop.Visio.Document
        Get
            If _drawingDocument Is Nothing And _drawingApplication IsNot Nothing Then
                Return _drawingApplication.ActiveDocument
            Else
                Return Me._drawingDocument
            End If
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Document)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("DocumentValueIsNull", _
                    "drawingDocument is Null.")
            End If
            Me._drawingDocument = value
        End Set
    End Property

    '********* visio snippet vb.net vis0044vb ******************
    Private _drawingPage As Microsoft.Office.Interop.Visio.Page
    Public Property drawingPage() As Microsoft.Office.Interop.Visio.Page
        Get
            Return Me._drawingPage
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Page)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("Value", _
                    "drawingPage is Null.")
            End If
            Me._drawingPage = value
        End Set
    End Property

    ' do we want to play with datarecordsets
    Private m_blnDR As Boolean
    Public Property _BlnDR() As Boolean
        Get
            _BlnDR = m_blnDR
        End Get
        Set(ByVal value As Boolean)
            m_blnDR = value
        End Set
    End Property

    Public m_stencilpath As String = ""
    Public Property _StencilPath() As String
        Get
            Return Me.m_stencilpath
        End Get
        Set(ByVal value As String)
            Me.m_stencilpath = value
        End Set
    End Property

#End Region

#Region " Enumerations "

    Public Enum DC_RackTables
        tblAttrApplication          ' application data apply to operating system
        tblAppConnection            ' for application topology
        tblAppSolution              ' for application topology
        tblAttrAsset                ' asset data, MAY apply to component
        tblAttrCabinet              ' cabinet attributes to apply to component
        tblAttrCabinetRow          ' row data as qualifier for sublocation data
        tblAttrDiskLogical          ' logical disk to apply to component
        tblAttrDiskPhysical         ' physical disk to apply to component
        tblAttrDraw                 ' draw data to apply to  component (specific document and page required)
        tblAttrExternalStorage      ' external disk to apply to component
        tblAttrGeoData              ' sql geo data to apply to sublocation data
        tblAttrLocation             ' sublocation data
        tblAttrNetwork              ' network definition for port and component
        tblAttrOperatingSystem      ' operating system to apply to component
        tblAttrPortData             ' port data to apply to component
        tblAttrProcessor            ' processor data to apply to component
        tblAttrVirtualHost          ' virtual host to apply to operating system
        tblClient                   ' client table as root to location
        tblComponents               ' component data
        tblCompHierarchy            ' sql component hierarchy for component relationships
        tblLocation                 ' location data to apply to clients
        tblNetworkLink              ' network link data to apply to portdata connectivity
        tblProductData              ' root product data (used to link between components and visio)
        tblDGMasters                ' root master stencil data to apply to tables (used to apply datagraphics to attributes)
        tblTopoEdge                 ' topology edge data (mirrors network link data)
        tblTopoPoint                ' topology port data (mirrors portdata)
        tblSlotMasterData           ' slot data as part of master analysis
        tblPortMasterData           ' port data as part of master analysis

        tblPortAnalysis             ' for completeness
        tblUnknown
    End Enum

    '
    '
    '
    Public Function getTableName(ByVal intEnum As DC_RackTables) As String

        Dim strReturn As String = ""

        Dim myName As DC_RackTables = intEnum
        strReturn = myName.ToString

        Return strReturn

    End Function

    '
    '
    '
    Public Structure rackURRI
        Public clientKey As Int32
        Public locKey As Int32
        Public attrlocKey As Int32
        Public rowKey As Int32
        Public rckKey As Int32
    End Structure

    '
    '
    '
    Public Function convertURRIFormat(ByVal strURRI As String) As clsDC_RackData.rackURRI

        ' init a structure to return
        Dim urriReturn As clsDC_RackData.rackURRI = New clsDC_RackData.rackURRI
        urriReturn.clientKey = -1
        urriReturn.locKey = -1
        urriReturn.attrlocKey = -1
        urriReturn.rowKey = -1
        urriReturn.rckKey = -1
        Dim intX As Integer

        Try



            Dim arrValue As String()


            ' parse out the fullpath

            strURRI = strURRI.Replace("[", "")
            strURRI = strURRI.Replace("]", "")
            arrValue = strURRI.Split({","c}, 5, StringSplitOptions.None)


            For intX = 1 To arrValue.Count
                Select Case intX
                    Case 1
                        urriReturn.clientKey = CInt(arrValue(intX))
                    Case 2
                        urriReturn.locKey = CInt(arrValue(intX))
                    Case 3
                        urriReturn.attrlocKey = CInt(arrValue(intX))
                    Case 4
                        urriReturn.rowKey = CInt(arrValue(intX))
                    Case 5
                        urriReturn.rckKey = CInt(arrValue(intX))
                End Select

            Next intX

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        Return urriReturn

    End Function

    '
    '
    '
    Public Function convertURRIFormat(ByVal rckURRI As clsDC_RackData.rackURRI) As String

        Dim strReturn As String = "[]"

        Try


            Dim retSB As StringBuilder = New StringBuilder
            retSB.Append("[" & rckURRI.clientKey.ToString & ",")
            retSB.Append(rckURRI.locKey.ToString & ",")
            retSB.Append(rckURRI.attrlocKey.ToString & ",")
            retSB.Append(rckURRI.rowKey.ToString & ",")
            retSB.Append(rckURRI.rckKey.ToString & "]")

            strReturn = retSB.ToString

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        Return strReturn

    End Function


#End Region

#Region " Load DataTable/Visio Recordsets "

    '******************************************************
    ' base tables
    '******************************************************

#Region " ProductData "



#End Region

#Region " DGMasters "


#End Region

#Region " Attribute Assets "


#End Region

#Region " Components "

    Private m_CompRS As Int32
    Public Property _CompRs() As Int32
        Get
            Return Me.m_CompRS
        End Get
        Set(ByVal value As Int32)
            Me.m_CompRS = value
        End Set
    End Property

    Private m_CompRecordset As Microsoft.Office.Interop.Visio.DataRecordset
    Public Property _CompRd() As Microsoft.Office.Interop.Visio.DataRecordset
        Get
            Return Me.m_CompRecordset
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.DataRecordset)
            Me.m_CompRecordset = value
            Me.m_CompRS = value.ID
        End Set
    End Property

    Private m_clsComp As clsComponents
    Public Property _clsComp() As clsComponents
        Get
            Return Me.m_clsComp
        End Get
        Set(ByVal value As clsComponents)
            Me.m_clsComp = value
        End Set
    End Property


    '
    '
    '
    Public Sub loadComponents _
            (Optional ByVal lngRowKey As Int32 = -1, _
             Optional ByVal colURRIKeys As Collection(Of rackURRI) = Nothing, _
             Optional ByVal dtSource As System.Data.DataTable = Nothing)

        Try

            If lngRowKey = -1 _
                And colURRIKeys Is Nothing _
                And dtSource Is Nothing Then
                Exit Sub
            End If

            If _clsComp Is Nothing Then
                _clsComp = New clsComponents(drawingApplication, drawingDocument)
            Else
                _clsComp = Nothing
                _clsComp = New clsComponents(drawingApplication, drawingDocument)
            End If

            Dim dtTemp As System.Data.DataTable = New System.Data.DataTable
            _clsComp.CreateTableColumns(dtTemp)

            Dim drTemp As DataRow
            Dim strTable As String = DC_RackTables.tblComponents.ToString
            dtTemp.TableName = strTable

            ' the default is to go read it from sql
            If dtSource Is Nothing Then
                If lngRowKey <> -1 Then
                    _clsComp.GetRowComponents(lngRowKey)
                Else
                    _clsComp.GetCompositeRow(colURRIKeys)
                End If
                dtTemp = _clsComp.m_dt.Copy
            Else
                ' need to do it row by row to force our schema over
                ' what excel does
                For Each drTemp In dtSource.Rows
                    dtTemp.ImportRow(drTemp)
                Next
            End If

            If m_ds.Tables(strTable) IsNot Nothing Then
                m_ds.Tables(strTable).Clear()
                For Each drTemp In dtTemp.Rows
                    m_ds.Tables(strTable).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(dtTemp.Copy)
            End If


            If _BlnDR = True Then
                Dim intCt As Integer = m_ds.Tables(strTable).Rows.Count
                If intCt = 0 Then Exit Sub
                Dim vsoRecordsets As Microsoft.Office.Interop.Visio.DataRecordsets = drawingDocument.DataRecordsets
                m_CompRecordset = vsoRecordsets.AddFromXML(m_clsVisio.ConvertToAdoRecordsetXML(m_ds.Tables(strTable)), 4, strTable)
            End If



        Catch com As COMException
            '********* visio snippet vb.net vis0056vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
            ' now get rid of the class
            m_clsComp = Nothing
            System.GC.Collect()
        End Try

    End Sub



#End Region

#Region " Network Links "


    Private m_clsLinks As clsNetworkLinks
    Public Property _clsLinks() As clsNetworkLinks
        Get
            Return m_clsLinks
        End Get
        Set(ByVal value As clsNetworkLinks)
            m_clsLinks = value
        End Set
    End Property

    Private m_LinkRS As Int32
    Public Property _LinkRs() As Int32
        Get
            Return Me.m_LinkRS
        End Get
        Set(ByVal value As Int32)
            Me.m_LinkRS = value
        End Set
    End Property

    Private m_LinkRecordset As Microsoft.Office.Interop.Visio.DataRecordset
    Public Property _LinkRd() As Microsoft.Office.Interop.Visio.DataRecordset
        Get
            Return Me.m_LinkRecordset
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.DataRecordset)
            m_LinkRecordset = value
            Me.m_LinkRS = value.ID
        End Set
    End Property

    '
    '
    '
    Public Sub loadNetworkLinksTable _
            (Optional ByVal lngRowKey As Int32 = -1, _
             Optional ByVal colURRIKeys As Collection(Of rackURRI) = Nothing, _
             Optional ByVal dtSource As System.Data.DataTable = Nothing)


        Try

            If lngRowKey = -1 _
                And colURRIKeys Is Nothing _
                And dtSource Is Nothing Then
                Exit Sub
            End If

            If _clsLinks Is Nothing Then
                _clsLinks = New clsNetworkLinks(drawingApplication, drawingDocument)
            Else
                _clsLinks = Nothing
                _clsLinks = New clsNetworkLinks(drawingApplication, drawingDocument)
            End If

            Dim dtTemp As System.Data.DataTable = New System.Data.DataTable
            _clsLinks.CreateTableColumns(dtTemp)

            Dim drTemp As DataRow
            Dim strTable As String = DC_RackTables.tblNetworkLink.ToString
            dtTemp.TableName = strTable

            ' the default is to go read it from sql
            If dtSource Is Nothing Then
                If lngRowKey <> -1 Then
                    _clsLinks.dbBuildLinksByURRICollection(colURRIKeys)
                Else
                    _clsLinks.dbBuildLinksByURRICollection(colURRIKeys)
                End If
                dtTemp = _clsLinks.m_ds.Tables(strTable).Copy
            Else
                ' need to do it row by row to force our schema over
                ' what excel does
                For Each drTemp In dtSource.Rows
                    dtTemp.ImportRow(drTemp)
                Next
            End If

            If Not (m_ds.Tables(strTable) Is Nothing) Then
                m_ds.Tables(strTable).Clear()
                For Each drTemp In dtTemp.Rows
                    m_ds.Tables(strTable).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(dtTemp.Copy)
            End If


            If _BlnDR = True Then
                Dim intCt As Integer = m_ds.Tables(strTable).Rows.Count
                If intCt = 0 Then Exit Sub
                Dim vsoRecordsets As Microsoft.Office.Interop.Visio.DataRecordsets = drawingDocument.DataRecordsets
                m_LinkRecordset = vsoRecordsets.AddFromXML(m_clsVisio.ConvertToAdoRecordsetXML(m_ds.Tables(strTable)), 4, strTable)
            End If

        Catch com As COMException
            '********* visio snippet vb.net vis0056vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If

        Finally
            ' now get rid of the class
            _clsLinks = Nothing
            System.GC.Collect()
        End Try


    End Sub



#End Region


    '******************************************************
    ' location data
    '******************************************************

#Region " Clients "

    Private m_ClientRS As Int32
    Public Property _ClientRs() As Int32
        Get
            Return Me.m_ClientRS
        End Get
        Set(ByVal value As Int32)
            Me.m_ClientRS = value
        End Set
    End Property

    Private m_ClientRecordset As Microsoft.Office.Interop.Visio.DataRecordset
    Public Property _ClientRd() As Microsoft.Office.Interop.Visio.DataRecordset
        Get
            Return Me.m_ClientRecordset
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.DataRecordset)
            Me.m_ClientRecordset = value
            Me.m_ClientRS = value.ID
        End Set
    End Property

    Private Shared m_clsClient As clsClients
    Public Property _clsClient() As clsClients
        Get
            Return clsDC_RackData.m_clsClient
        End Get
        Set(ByVal value As clsClients)
            clsDC_RackData.m_clsClient = value
        End Set
    End Property

    '
    '
    '
    Public Sub loadClients _
                  (Optional ByVal dtSource As System.Data.DataTable = Nothing)

        Try


            If _clsClient Is Nothing Then
                _clsClient = New clsClients
            Else
                _clsClient = Nothing
                _clsClient = New clsClients
            End If

            Dim dtTemp As System.Data.DataTable = New System.Data.DataTable
            _clsClient.CreateTableColumns(dtTemp)

            Dim drTemp As DataRow
            Dim strTable As String = DC_RackTables.tblClient.ToString
            dtTemp.TableName = strTable

            ' the default is to go read it from sql
            If dtSource Is Nothing Then
                _clsClient.dbSelectAllClients()
                dtTemp = _clsClient.m_dt.Copy
            Else
                ' need to do it row by row to force our schema over
                ' what excel does
                For Each drTemp In dtSource.Rows
                    dtTemp.ImportRow(drTemp)
                Next

            End If

            If m_ds.Tables(strTable) IsNot Nothing Then
                m_ds.Tables(strTable).Clear()
                For Each drTemp In dtTemp.Rows
                    m_ds.Tables(strTable).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(dtTemp.Copy)
            End If


            If _BlnDR = True Then
                Dim intCt As Integer = m_ds.Tables(strTable).Rows.Count
                If intCt = 0 Then Exit Sub
                Dim vsoRecordsets As Microsoft.Office.Interop.Visio.DataRecordsets = drawingDocument.DataRecordsets
                m_ClientRecordset = vsoRecordsets.AddFromXML(m_clsVisio.ConvertToAdoRecordsetXML(m_ds.Tables(strTable)), 4, strTable)
            End If

        Catch com As COMException
            '********* visio snippet vb.net vis0056vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
            ' now get rid of the class
            m_clsClient = Nothing
            System.GC.Collect()
        End Try

    End Sub


#End Region

#Region " Location "


    Private m_clsSites As clsLocations
    Public Property _clsSites() As clsLocations
        Get
            Return m_clsSites
        End Get
        Set(ByVal value As clsLocations)
            m_clsSites = value
        End Set
    End Property

    Private m_SiteRS As Int32
    Public Property _SiteRS() As Int32
        Get
            _SiteRS = m_SiteRS
        End Get
        Set(ByVal value As Int32)
            m_SiteRS = value
        End Set
    End Property

    Private m_SiteRecordset As Microsoft.Office.Interop.Visio.DataRecordset
    Public Property _SiteRd() As Microsoft.Office.Interop.Visio.DataRecordset
        Get
            _SiteRd = m_SiteRecordset
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.DataRecordset)
            m_SiteRecordset = value
            Me.m_SiteRS = value.ID
        End Set
    End Property

    '
    '
    '
    Public Sub loadLocationTable _
                    (Optional ByVal dtSource As System.Data.DataTable = Nothing)

        Try


            If _clsSites Is Nothing Then
                _clsSites = New clsLocations
            Else
                _clsSites = Nothing
                _clsSites = New clsLocations
            End If

            Dim dtTemp As System.Data.DataTable = New System.Data.DataTable
            _clsSites.CreateTableColumns(dtTemp)

            Dim drTemp As DataRow
            Dim strTable As String = DC_RackTables.tblLocation.ToString
            dtTemp.TableName = strTable

            ' the default is to go read it from sql
            If dtSource Is Nothing Then
                _clsSites.dbSelectAllLocations()
                dtTemp = _clsSites.m_dt.Copy
            Else
                ' need to do it row by row to force our schema over
                ' what excel does
                For Each drTemp In dtSource.Rows
                    dtTemp.ImportRow(drTemp)
                Next

            End If

            ' load it locally
            If m_ds.Tables(strTable) IsNot Nothing Then
                m_ds.Tables(strTable).Clear()
                For Each drTemp In dtTemp.Rows
                    m_ds.Tables(strTable).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(dtTemp.Copy)
            End If


            If _BlnDR = True Then
                Dim intCt As Integer = m_ds.Tables(strTable).Rows.Count
                If intCt = 0 Then Exit Sub
                Dim vsoRecordsets As Microsoft.Office.Interop.Visio.DataRecordsets = drawingDocument.DataRecordsets
                m_SiteRecordset = vsoRecordsets.AddFromXML(m_clsVisio.ConvertToAdoRecordsetXML(m_ds.Tables(strTable)), 4, strTable)
            End If

        Catch com As COMException
            '********* visio snippet vb.net vis0056vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
            ' now get rid of the class
            _clsSites = Nothing
            System.GC.Collect()
        End Try


    End Sub

#End Region

#Region " Attribute Location "



    Private m_clsSubLocations As clsAttrLocation
    Public Property _clsSubLocations() As clsAttrLocation
        Get
            Return m_clsSubLocations
        End Get
        Set(ByVal value As clsAttrLocation)
            Me.m_clsSubLocations = value
        End Set
    End Property

    Private m_SubLocationRS As Int32
    Public Property _SubLocationRs() As Int32
        Get
            Return Me.m_SubLocationRS
        End Get
        Set(ByVal value As Int32)
            Me.m_SubLocationRS = value
        End Set
    End Property

    Private m_SubLocationRecordset As Microsoft.Office.Interop.Visio.DataRecordset
    Public Property _SubLocationRd() As Microsoft.Office.Interop.Visio.DataRecordset
        Get
            Return Me.m_SubLocationRecordset
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.DataRecordset)
            Me.m_SubLocationRecordset = value
            Me.m_SubLocationRS = value.ID
        End Set
    End Property

    '
    '
    '
    Public Sub loadSubLocationTable _
                      (Optional ByVal intSiteKey As Int32 = -1, _
                      Optional ByVal dtSource As System.Data.DataTable = Nothing)

        Try


            If _clsSubLocations Is Nothing Then
                _clsSubLocations = New clsAttrLocation(drawingApplication, drawingDocument)
            Else
                _clsSubLocations = Nothing
                _clsSubLocations = New clsAttrLocation(drawingApplication, drawingDocument)
            End If

            Dim dtTemp As System.Data.DataTable = New System.Data.DataTable
            _clsSubLocations.CreateTableColumns(dtTemp)

            Dim drTemp As DataRow
            Dim strTable As String = DC_RackTables.tblAttrLocation.ToString
            dtTemp.TableName = strTable

            ' the default is to go read it from sql
            If dtSource Is Nothing Then
                If -1 < intSiteKey Then
                    _clsSubLocations.dbSelectAttrLocationByLocSiteKey(intSiteKey)
                    dtTemp = _clsSubLocations.m_dt.Copy
                Else
                    _clsSubLocations.dbSelectAllAttrLocation()
                    dtTemp = _clsSubLocations.m_dt.Copy
                End If
            Else
                ' need to do it row by row to force our schema over
                ' what excel does
                For Each drTemp In dtSource.Rows
                    dtTemp.ImportRow(drTemp)
                Next

            End If

            ' load it locally
            If m_ds.Tables(strTable) IsNot Nothing Then
                m_ds.Tables(strTable).Clear()
                For Each drTemp In dtTemp.Rows
                    m_ds.Tables(strTable).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(dtTemp.Copy)
            End If

            If _BlnDR = True Then
                Dim intCt As Integer = m_ds.Tables(strTable).Rows.Count
                If intCt = 0 Then Exit Sub
                Dim vsoRecordsets As Microsoft.Office.Interop.Visio.DataRecordsets = drawingDocument.DataRecordsets
                m_SubLocationRecordset = vsoRecordsets.AddFromXML(m_clsVisio.ConvertToAdoRecordsetXML(m_ds.Tables(strTable)), 4, strTable)
            End If

        Catch com As COMException
            '********* visio snippet vb.net vis0056vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
            ' now get rid of the class
            _clsSubLocations = Nothing
            System.GC.Collect()
        End Try


    End Sub


#End Region

#Region " Attribute Cabinet Rows "

    Private m_clsCabRows As clsAttrCabinetRows
    Public Property _clsCabRows() As clsAttrCabinetRows
        Get
            Return m_clsCabRows
        End Get
        Set(ByVal value As clsAttrCabinetRows)
            m_clsCabRows = value
        End Set
    End Property

    Private m_CabRowsRS As Int32
    Public Property _CabRowsRs() As Int32
        Get
            _CabRowsRs = m_CabRowsRS
        End Get
        Set(ByVal value As Int32)
            m_CabRowsRS = value
        End Set
    End Property

    Private m_CabRowsRecordset As Microsoft.Office.Interop.Visio.DataRecordset
    Public Property _CabRowsRd() As Microsoft.Office.Interop.Visio.DataRecordset
        Get
            _CabRowsRd = m_CabRowsRecordset
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.DataRecordset)
            m_CabRowsRecordset = value
            Me.m_CabRowsRS = value.ID
        End Set
    End Property

    '
    '
    '
    Public Sub loadCabrowsTable _
                  (Optional ByVal intLocId As Int32 = -1, _
                   Optional ByVal dtSource As System.Data.DataTable = Nothing)

        Try

            If intLocId = -1 _
                And dtSource Is Nothing Then
                Exit Sub
            End If


            If _clsCabRows Is Nothing Then
                _clsCabRows = New clsAttrCabinetRows
            Else
                _clsCabRows = Nothing
                _clsCabRows = New clsAttrCabinetRows
            End If

            Dim dtTemp As System.Data.DataTable = New System.Data.DataTable
            _clsCabRows.CreateTableColumns(dtTemp)

            Dim drTemp As DataRow
            Dim strTable As String = DC_RackTables.tblAttrCabinetRow.ToString
            dtTemp.TableName = strTable

            ' the default is to go read it from sql
            If dtSource Is Nothing Then
                If intLocId <> -1 Then
                    _clsCabRows.dbSelectCabinetRowsBySublocation(intLocId)
                    dtTemp = _clsCabRows.m_dt.Copy
                End If
            Else
                ' need to do it row by row to force our schema over
                ' what excel does
                For Each drTemp In dtSource.Rows
                    dtTemp.ImportRow(drTemp)
                Next
            End If

            ' load it locally
            If m_ds.Tables(strTable) IsNot Nothing Then
                m_ds.Tables(strTable).Clear()
                For Each drTemp In dtTemp.Rows
                    m_ds.Tables(strTable).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(dtTemp.Copy)
            End If


            If _BlnDR = True Then
                Dim intCt As Integer = m_ds.Tables(strTable).Rows.Count
                If intCt = 0 Then Exit Sub
                Dim vsoRecordsets As Microsoft.Office.Interop.Visio.DataRecordsets = drawingDocument.DataRecordsets
                m_CabRowsRecordset = vsoRecordsets.AddFromXML(m_clsVisio.ConvertToAdoRecordsetXML(m_ds.Tables(strTable)), 4, strTable)
            End If

        Catch com As COMException
            '********* visio snippet vb.net vis0056vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
            ' now get rid of the class
            _clsCabRows = Nothing
            System.GC.Collect()
        End Try


    End Sub

#End Region

#Region " Attribute Geography Data "

    Private m_clsGeoData As clsAttrGeoData
    Public Property _clsGeoData() As clsAttrGeoData
        Get
            Return m_clsGeoData
        End Get
        Set(ByVal value As clsAttrGeoData)
            m_clsGeoData = value
        End Set
    End Property

    Private m_GeoDataRS As Int32
    Public Property _GeoDataRS() As Int32
        Get
            _GeoDataRS = m_GeoDataRS
        End Get
        Set(ByVal value As Int32)
            m_GeoDataRS = value
        End Set
    End Property

    Private m_GeoDataRecordset As Microsoft.Office.Interop.Visio.DataRecordset
    Public Property _GeoDataRd() As Microsoft.Office.Interop.Visio.DataRecordset
        Get
            _GeoDataRd = m_GeoDataRecordset
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.DataRecordset)
            m_GeoDataRecordset = value
            Me.m_GeoDataRS = value.ID
        End Set
    End Property

    '
    '
    '
    Public Sub loadGeoDataTable _
                  (Optional ByVal dtSource As System.Data.DataTable = Nothing)

        Try


            If _clsGeoData Is Nothing Then
                _clsGeoData = New clsAttrGeoData
            Else
                _clsGeoData = Nothing
                _clsGeoData = New clsAttrGeoData
            End If

            Dim dtTemp As System.Data.DataTable = New System.Data.DataTable
            _clsGeoData.CreateTableColumns(dtTemp)

            Dim drTemp As DataRow
            Dim strTable As String = DC_RackTables.tblAttrGeoData.ToString
            dtTemp.TableName = strTable

            ' the default is to go read it from sql
            If dtSource Is Nothing Then
                _clsGeoData.dbSelectAllGeoData()
                dtTemp = _clsGeoData.m_dt.Copy
            Else
                ' need to do it row by row to force our schema over
                ' what excel does
                For Each drTemp In dtSource.Rows
                    ' move the record over to the geodata class to fix sqlgeography conversion
                    _clsGeoData.moveDataRowToProperties(drTemp)
                    Dim drConv As DataRow = dtTemp.NewRow
                    _clsGeoData.movePropertiesToDataRow(drConv, _clsGeoData.m_dc)
                    dtTemp.Rows.Add(drConv)
                Next

            End If

            ' load it locally
            If m_ds.Tables(strTable) IsNot Nothing Then
                m_ds.Tables(strTable).Clear()
                For Each drTemp In dtTemp.Rows
                    m_ds.Tables(strTable).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(dtTemp.Copy)
            End If


            If _BlnDR = True Then
                Dim intCt As Integer = m_ds.Tables(strTable).Rows.Count
                If intCt = 0 Then Exit Sub
                Dim vsoRecordsets As Microsoft.Office.Interop.Visio.DataRecordsets = drawingDocument.DataRecordsets
                m_GeoDataRecordset = vsoRecordsets.AddFromXML(m_clsVisio.ConvertToAdoRecordsetXML(m_ds.Tables(strTable)), 4, strTable)
            End If

        Catch com As COMException
            '********* visio snippet vb.net vis0056vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
            ' now get rid of the class
            _clsGeoData = Nothing
            System.GC.Collect()
        End Try


    End Sub



#End Region


    '******************************************************
    ' Network data
    '******************************************************


#Region " Attribute Port Data "



    Private m_clsPorts As clsAttrPortData
    Public Property _clsPorts() As clsAttrPortData
        Get
            Return m_clsPorts
        End Get
        Set(ByVal value As clsAttrPortData)
            m_clsPorts = value
        End Set
    End Property

    Private m_PortRS As Int32
    Public Property _PortRs() As Int32
        Get
            _PortRs = m_PortRS
        End Get
        Set(ByVal value As Int32)
            m_PortRS = value
        End Set
    End Property

    Private m_PortRecordset As Microsoft.Office.Interop.Visio.DataRecordset
    Public Property _PortRd() As Microsoft.Office.Interop.Visio.DataRecordset
        Get
            _PortRd = m_PortRecordset
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.DataRecordset)
            m_PortRecordset = value
            Me.m_PortRS = value.ID
        End Set
    End Property

    '
    '
    '
    Public Sub loadAttrPortData _
            (Optional ByVal lngRowKey As Int32 = -1, _
             Optional ByVal colURRIKeys As Collection(Of rackURRI) = Nothing, _
             Optional ByVal dtSource As System.Data.DataTable = Nothing)

        Try

            If lngRowKey = -1 _
                And colURRIKeys Is Nothing _
                And dtSource Is Nothing Then
                Exit Sub
            End If

            If _clsPorts Is Nothing Then
                _clsPorts = New clsAttrPortData(drawingApplication, drawingDocument)
            Else
                _clsPorts = Nothing
                _clsPorts = New clsAttrPortData(drawingApplication, drawingDocument)
            End If

            Dim dtTemp As System.Data.DataTable = New System.Data.DataTable
            _clsPorts.CreateTableColumns(dtTemp)

            Dim drTemp As DataRow
            Dim strTable As String = DC_RackTables.tblAttrPortData.ToString
            dtTemp.TableName = strTable

            ' the default is to go read it from sql
            If dtSource Is Nothing Then
                If lngRowKey <> -1 Then
                    _clsPorts.dbSelectAttrPortDataByRowKey(lngRowKey)
                Else
                    _clsPorts.dbSelectAttrPortDataByCompositeRow(colURRIKeys)
                End If
                dtTemp = _clsPorts.m_dt.Copy
            Else
                ' need to do it row by row to force our schema over
                ' what excel does
                For Each drTemp In dtSource.Rows
                    dtTemp.ImportRow(drTemp)
                Next

            End If

            If m_ds.Tables(strTable) IsNot Nothing Then
                m_ds.Tables(strTable).Clear()
                For Each drTemp In dtTemp.Rows
                    m_ds.Tables(strTable).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(dtTemp.Copy)
            End If

            If _BlnDR = True Then
                Dim intCt As Integer = m_ds.Tables(strTable).Rows.Count
                If intCt = 0 Then Exit Sub

                Dim vsoRecordsets As Microsoft.Office.Interop.Visio.DataRecordsets = drawingDocument.DataRecordsets
                m_PortRecordset = vsoRecordsets.AddFromXML(m_clsVisio.ConvertToAdoRecordsetXML(m_ds.Tables(strTable)), 4, strTable)
            End If

        Catch com As COMException
            '********* visio snippet vb.net vis0056vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
            ' now get rid of the class
            m_clsPorts = Nothing
            System.GC.Collect()
        End Try

    End Sub





#End Region

#Region " Attribute Network "


    Private m_clsAttrNet As clsAttrNetwork
    Public Property _clsAttrNet() As clsAttrNetwork
        Get
            Return m_clsAttrNet
        End Get
        Set(ByVal value As clsAttrNetwork)
            m_clsAttrNet = value
        End Set
    End Property


    Private m_AttrNetRS As Int32
    Public Property _AttrNetRs() As Int32
        Get
            Return Me.m_AttrNetRS
        End Get
        Set(ByVal value As Int32)
            Me.m_AttrNetRS = value
        End Set
    End Property

    Private m_AttrNetRecordset As Microsoft.Office.Interop.Visio.DataRecordset
    Public Property _AttrNetRd() As Microsoft.Office.Interop.Visio.DataRecordset
        Get
            Return Me.m_AttrNetRecordset
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.DataRecordset)
            Me.m_AttrNetRecordset = value
            Me.m_AttrNetRS = value.ID
        End Set
    End Property


    '
    '
    '
    Public Sub loadAttrNetwork _
            (Optional ByVal lngRowKey As Int32 = -1, _
             Optional ByVal colURRIKeys As Collection(Of rackURRI) = Nothing, _
             Optional ByVal dtSource As System.Data.DataTable = Nothing)

        Try

            If lngRowKey = -1 _
                And colURRIKeys Is Nothing _
                And dtSource Is Nothing Then
                Exit Sub
            End If

            If _clsAttrNet Is Nothing Then
                _clsAttrNet = New clsAttrNetwork(drawingApplication, drawingDocument)
            Else
                _clsAttrNet.initDataSetAndTable()
            End If

            Dim dtTemp As System.Data.DataTable = New System.Data.DataTable
            _clsAttrNet.CreateTableColumns(dtTemp)

            Dim drTemp As DataRow
            Dim strTable As String = DC_RackTables.tblAttrNetwork.ToString
            dtTemp.TableName = strTable

            ' the default is to go read it from sql
            If dtSource Is Nothing Then
                If lngRowKey <> -1 Then
                    _clsAttrNet.dbSelectAttrNetworkByRowKey(lngRowKey)
                Else
                    _clsAttrNet.dbSelectAttrNetworkByUrriKeys(colURRIKeys)
                End If
                dtTemp = _clsAttrNet.m_dt.Copy
            Else
                ' need to do it row by row to force our schema over
                ' what excel does
                For Each drTemp In dtSource.Rows
                    dtTemp.ImportRow(drTemp)
                Next

            End If


            If m_ds.Tables(strTable) IsNot Nothing Then
                m_ds.Tables(strTable).Clear()
                For Each drTemp In dtTemp.Rows
                    m_ds.Tables(strTable).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(dtTemp.Copy)
            End If



            If _BlnDR = True Then

                Dim intCt As Integer = m_ds.Tables(strTable).Rows.Count
                If intCt = 0 Then Exit Sub

                Dim vsoRecordsets As Microsoft.Office.Interop.Visio.DataRecordsets = drawingDocument.DataRecordsets
                m_AttrNetRecordset = vsoRecordsets.AddFromXML(m_clsVisio.ConvertToAdoRecordsetXML(m_ds.Tables(strTable)), 4, strTable)
            End If

        Catch com As COMException
            '********* visio snippet vb.net vis0056vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
            _clsAttrNet = Nothing
            System.GC.Collect()
        End Try

    End Sub


    '
    '
    '
    Public Sub loadAttrNetVisioProperties _
                (ByRef visNetShape As Microsoft.Office.Interop.Visio.Shape, _
                Optional ByVal blnProperties As Boolean = True, _
                Optional ByVal blnStatus As Boolean = True, _
                Optional ByVal blnTestData As Boolean = False)


        Try

            Dim intCompKey As Int32 = -1
            Dim visCell As Microsoft.Office.Interop.Visio.Cell
            Dim intType As dc_Product.vnetType = visRackLocations.dc_Product.vnetType.ptUnknown
            Dim strType As String = ""
            Dim strFormula As String = ""

            '
            ' the shape is neither passive nor a link
            '
            If visNetShape.CellExists("prop.comptype", False) = True Then
                visCell = visNetShape.Cells("prop.comptype")
                strType = Replace(visCell.FormulaU, """", "")
                intType = CInt(strType)
                ' have to have a positive vnettype and is not passive or media
                If 0 < intType _
                    And intType <> visRackLocations.dc_Product.vnetType.ptNetworkPassive _
                    And intType <> visRackLocations.dc_Product.vnetType.ptNetworkLink Then
                    'Debug.Print(intType)
                Else
                    ' not a valid vNetType
                    Exit Sub
                End If
            Else
                Exit Sub
            End If

            ' make sure the attribute class is loaded
            If _clsAttrNet Is Nothing Then
                _clsAttrNet = New clsAttrNetwork(drawingApplication, drawingDocument)
                _clsAttrNet.m_dc.initProperties()
            Else
                _clsAttrNet.m_dc.initProperties()
            End If

            _clsAttrNet.drawingPage = visNetShape.ContainingPage

            If blnTestData = False Then

                '
                ' check to see if the network attribute data table was loaded
                '
                If m_ds.Tables(DC_RackTables.tblAttrNetwork.ToString) Is Nothing Then
                    MsgBox("Network attributes were not loaded")
                    Exit Sub
                End If

                '
                ' it is loaded and has rows in it
                '
                If m_ds.Tables(DC_RackTables.tblAttrNetwork.ToString).Rows.Count < 1 Then Exit Sub

                '
                ' the shape has a component key that can be chased
                '
                If visNetShape.CellExists("prop.compkey", False) = True Then
                    visCell = visNetShape.Cells("prop.compkey")
                    strFormula = visCell.FormulaU
                    strFormula = strFormula.Replace("""", "")
                    intCompKey = CInt(strFormula)
                Else
                    Exit Sub
                End If


                Dim netQuery = From attrnet In m_ds.Tables(DC_RackTables.tblAttrNetwork.ToString).AsEnumerable() _
                        Where attrnet!attrnetcompkey = intCompKey _
                        Select attrnet

                'execute and find only one component in the table with that key
                If netQuery.Count = 1 Then
                    For Each p In netQuery
                        ' clear the working record
                        _clsAttrNet.m_dc.initProperties()
                        ' pass in the shape we are working with
                        _clsAttrNet._VisShape = visNetShape
                        If blnProperties = True Then
                            _clsAttrNet.UpdateNetworkProperties(visNetShape, p, "datarow")
                        End If
                        ' we are just updating the status functions
                        If blnStatus = True And blnProperties = False Then
                            _clsAttrNet.MakeNetworkStatusAware(visNetShape, p)
                        End If

                    Next p
                End If

            Else
                ' flagged to put testdata into the shape
                _clsAttrNet.addTestNetworkProperties()
                _clsAttrNet.UpdateNetworkProperties(visNetShape, Nothing, "addattr")

            End If


        Catch com As COMException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
            MsgBox("Add Net Attributes Error " & ex.Message & " " & visNetShape.Name)
        Finally
            _clsAttrNet = Nothing
        End Try

        System.GC.Collect()

    End Sub


#End Region

    '******************************************************
    ' Miscellaneous
    '******************************************************

#Region " Attribute Cabinets "

    Private m_RackRS As Int32
    Public Property _RackRs() As Int32
        Get
            Return Me.m_RackRS
        End Get
        Set(ByVal value As Int32)
            Me.m_RackRS = value
        End Set
    End Property

    Private m_RackRecordset As Microsoft.Office.Interop.Visio.DataRecordset
    Public Property _RackRd() As Microsoft.Office.Interop.Visio.DataRecordset
        Get
            Return Me.m_RackRecordset
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.DataRecordset)
            m_RackRecordset = value
            Me.m_RackRS = value.ID
        End Set
    End Property

    Private m_clsCabs As clsAttrCabinet
    Public Property _clsCabs() As clsAttrCabinet
        Get
            Return m_clsCabs
        End Get
        Set(ByVal value As clsAttrCabinet)
            m_clsCabs = value
        End Set
    End Property

    '
    ' this uses the viewCabinetData source in SQL Server
    '
    Public Sub loadCabinetView _
            (Optional ByVal lngRowKey As Int32 = -1, _
             Optional ByVal colURRIKeys As Collection(Of rackURRI) = Nothing, _
             Optional ByVal dtSource As System.Data.DataTable = Nothing)


        Try

            If lngRowKey = -1 _
                And colURRIKeys Is Nothing _
                And dtSource Is Nothing Then
                Exit Sub
            End If


            If _clsCabs Is Nothing Then
                _clsCabs = New clsAttrCabinet
            Else
                _clsCabs = Nothing
                _clsCabs = New clsAttrCabinet
            End If

            Dim dtTemp As System.Data.DataTable = New System.Data.DataTable
            Dim drTemp As DataRow
            Dim strTable As String = "viewCabinets"
            'Dim strTable As String = DC_RackTables.tblAttrCabinet.ToString
            dtTemp.TableName = strTable

            ' the default is to go read it from sql
            If dtSource Is Nothing Then
                If lngRowKey <> -1 Then
                    _clsCabs.dbSelectCabinetsByRowKey(lngRowKey)
                Else
                    _clsCabs.dbBuildCabinetsByURRICollection(colURRIKeys)
                End If
                dtTemp = _clsCabs.m_dt.Copy
            Else
                ' need to do it row by row to force our schema over
                ' what excel does
                For Each drTemp In dtSource.Rows
                    dtTemp.ImportRow(drTemp)
                Next

            End If

            If m_ds.Tables(strTable) IsNot Nothing Then
                m_ds.Tables(strTable).Clear()
                For Each drTemp In dtTemp.Rows
                    m_ds.Tables(strTable).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(dtTemp.Copy)
            End If


            If _BlnDR = True Then

                Dim intCt As Integer = m_ds.Tables(strTable).Rows.Count
                If intCt = 0 Then Exit Sub

                Dim vsoRecordsets As Microsoft.Office.Interop.Visio.DataRecordsets = drawingDocument.DataRecordsets
                m_RackRecordset = vsoRecordsets.AddFromXML(m_clsVisio.ConvertToAdoRecordsetXML(m_ds.Tables(strTable)), 4, strTable)
            End If

        Catch com As COMException
            '********* visio snippet vb.net vis0056vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
            ' now get rid of the class
            _clsCabs = Nothing
            System.GC.Collect()
        End Try

    End Sub


    '
    ' this uses the tblAttrCabinets source in SQL Server
    '
    Public Sub loadCabinets _
        (Optional ByVal lngRowKey As Int32 = -1, _
         Optional ByVal colURRIKeys As Collection(Of rackURRI) = Nothing, _
         Optional ByVal dtSource As System.Data.DataTable = Nothing)


        Try

            If lngRowKey = -1 _
                And colURRIKeys Is Nothing _
                And dtSource Is Nothing Then
                Exit Sub
            End If


            If _clsCabs Is Nothing Then
                _clsCabs = New clsAttrCabinet
            Else
                _clsCabs = Nothing
                _clsCabs = New clsAttrCabinet
            End If

            Dim dtTemp As System.Data.DataTable = New System.Data.DataTable
            _clsCabs.CreateTableColumns(dtTemp)

            Dim drTemp As DataRow
            Dim strTable As String = DC_RackTables.tblAttrCabinet.ToString
            dtTemp.TableName = strTable

            ' the default is to go read it from sql
            If dtSource Is Nothing Then
                If lngRowKey <> -1 Then
                    _clsCabs.dbSelectCabinetsByRowKey(lngRowKey)
                Else
                    _clsCabs.dbBuildCabinetsByURRICollection(colURRIKeys)
                End If
                dtTemp = _clsCabs.m_dt.Copy
            Else
                ' need to do it row by row to force our schema over
                ' what excel does
                For Each drTemp In dtSource.Rows
                    dtTemp.ImportRow(drTemp)
                Next

            End If

            If m_ds.Tables(strTable) IsNot Nothing Then
                m_ds.Tables(strTable).Clear()
                For Each drTemp In dtTemp.Rows
                    m_ds.Tables(strTable).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(dtTemp.Copy)
            End If


            If _BlnDR = True Then

                Dim intCt As Integer = m_ds.Tables(strTable).Rows.Count
                If intCt = 0 Then Exit Sub

                Dim vsoRecordsets As Microsoft.Office.Interop.Visio.DataRecordsets = drawingDocument.DataRecordsets
                m_RackRecordset = vsoRecordsets.AddFromXML(m_clsVisio.ConvertToAdoRecordsetXML(m_ds.Tables(strTable)), 4, strTable)
            End If

        Catch com As COMException
            '********* visio snippet vb.net vis0056vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
            ' now get rid of the class
            _clsCabs = Nothing
            System.GC.Collect()
        End Try

    End Sub


#End Region

#Region " Attribute Draw "


#End Region

#Region " Attribute Processor "



#End Region

    '******************************************************
    ' Disk information
    '******************************************************

#Region " Attribute (Disk) External Storage "


#End Region

#Region " Attribute Disk Logical "



#End Region

#Region " Attribute Disk Physical "



#End Region

    '******************************************************
    ' Software
    '******************************************************

#Region " Attribute Operating System "

#End Region

#Region " Attribute Applications "



#End Region

#Region " Attribute Virtual Hosts "


#End Region

#Region " Application Connections "


#End Region

#Region " Application Solutions "



#End Region


    '******************************************************
    ' 
    '******************************************************

#End Region

#Region " Constructor "

    Public Sub New()



        Try

            m_clsVisio = New visRackLocations.clsVisioSupport

            m_db = DatabaseFactory.CreateDatabase()

            If m_ds Is Nothing Then
                m_ds = New DataSet
            Else
                m_ds = Nothing
                m_ds = New DataSet
            End If

            If m_dt Is Nothing Then
                m_dt = New DataTable
            Else
                m_dt = Nothing
                m_dt = New DataTable
            End If

            _BlnDR = False
            _StencilPath = My.Settings.path_custom_stencils


        Catch com As COMException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try


    End Sub


#End Region


    Protected Overrides Sub Finalize()

        MyBase.Finalize()

    End Sub

    '
    '
    '
    Private Sub NullAndRelease(ByVal runtimeObject As Object)

        Try

            If Not (runtimeObject Is Nothing) Then

                ' The RCW's reference count gets incremented each time the
                ' COM pointer is passed from unmanaged to managed code.
                ' Call ReleaseComObject in a loop until it returns 0 to be
                ' sure that the underlying COM object gets released.
                Dim i As Integer
                Do
                    i = System.Runtime.InteropServices.Marshal. _
                        ReleaseComObject(runtimeObject)
                Loop While i > 0
            End If
        Finally
            runtimeObject = Nothing
        End Try
    End Sub



End Class

